# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>
# Contributor: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Diego Sogari <diego.sogari@gmail.com>

_realname=qhull
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r166.f1f8b42
pkgrel=1
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgdesc="A general dimension code for computing convex hulls and related structures (mingw-w64)"
arch=('any')
url="http://www.qhull.org/"
license=('custom')
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("git"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
source=("${_realname}"::"git+https://github.com/qhull/qhull.git"
        "0001-MSYS2-Adopt-FHS-layout-in-cmake.patch"
        "0002-resolve-conflict-system-io_h.patch")
sha256sums=('SKIP'
            'd14cc348b33c003dccdfbd95801a26b5ac0831f069cabc07da0c172f3823c8b3'
            'b1eb1b2b02e806bd3c8adddd158db7c57bcbea103653120e9326d7db60391f29')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -Np1 -i "${srcdir}/0001-MSYS2-Adopt-FHS-layout-in-cmake.patch"
  patch -Np1 -i "${srcdir}/0002-resolve-conflict-system-io_h.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    "../${_realname}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
